<?php
/**
 * Created by PhpStorm.
 * User: Shroom Ari
 * Date: 11/20/14
 * Time: 11:24 AM
 */
class Minvoicedetail extends MY_Model{
    public $table = 'invoice_detail';

    function getInvoiceDetailById($id){
        $query = $this->db->query("select tbl3.product_id, tbl3.product_name, tbl3.description, tbl3.url_image, tbl3.product_category_id, tbl3.quantity_remaining, quantity, amount, round(if(new_price is null, tbl3.unit_price, new_price),2) as unit_price from (select product.*, invoice_detail.quantity,invoice_detail.amount from invoice_detail, product where invoice_id = $id and invoice_detail.product_id = product.product_id ) tbl3 left join (select tb1.*, new_price from product tb1 left join (select product.product_id, round((1- promotion.discount)*product.unit_price,2) as new_price from promotion_detail, promotion, product where promotion.promotion_id in (select promotion_id from promotion where start_date <= now() and end_date>= now()) and promotion.promotion_id = promotion_detail.promotion_id and promotion_detail.product_id = product.product_id) tb2 on tb1.product_id = tb2.product_id) tbl4 on tbl3.product_id = tbl4.product_id");
        return $query->result_array();
    }

    function getInvoiceDetail($id){
        $query = $this->db->query("select * from invoice_detail where invoice_id = $id");
        return $query->result_array();
    }

}